<?php

namespace app\store\controller\shop;

use app\store\controller\Controller;
use app\store\model\store\shop\CardOrder as CardOrderModel;
use app\common\service\qrcode\Card as Cardmodel;

class Card extends Controller
{
    /**
     * 订单核销记录列表
     * @param int $shop_id
     * @param string $search
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index($search = '')
    {
        // 核销记录列表
        $data = $this->getData();
        $model = new CardOrderModel;
        $list = $model->getList('all', $data);
        $title = "全部订单列表";$dataType='all';
        return $this->fetch('index', compact('list','title','dataType'));
    }

    /**
     * 卡座订单审核
     * @param int $shop_id
     * @return array|bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function examine($id = 0){
        $qrcode = new Cardmodel();
        $model = new CardOrderModel;
        $info = $model->find($id);
        $fileulr =  $qrcode->saveq($info->wxapp_id, 'order_no:' . $info->order_no);
        $info->order_status = CardOrderModel::CARD_ORDER_WRITE;
        $info->qrcode_url = $fileulr;
        $result = $info->save();
        if($result){
            return $this->renderSuccess('审核成功');
        }else{
            return $this->renderError($model->getError() ?: '审核失败');
        }
    }
}